package com.yfp.client.controller;

import cn.hutool.core.util.BooleanUtil;
import com.yfp.client.domain.dto.PackSettleDTO;
import com.yfp.client.service.PackOrderService;
import com.yfp.client.util.Response;
import com.yfp.common.core.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 礼包订单模块
 */
@RestController
@RequestMapping("/client/couponPack-order")
@Tag(name = "礼包订单模块")
public class PackOrderController extends BaseController {

    @Resource
    private PackOrderService packOrderService;

    @PostMapping("/settle")
    @Operation(summary = "套餐结算-去支付", description = "小程序创建订单使用-订单结算-去支付")
    public Response<String> settleCombo(@RequestBody PackSettleDTO packSettleDTO) {
        String orderSn = packOrderService.settleCombo(packSettleDTO);
        return Response.success(orderSn);
    }

    @GetMapping("/settle/check")
    @Operation(summary = "套餐结算-去支付校验", description = "小程序创建订单使用-订单结算-去支付前校验")
    public Response<Integer> settleComboCheck(@RequestParam String orderId) {
        Boolean canBuy = packOrderService.settleComboCheck(orderId);
        Integer canBuyInteger = BooleanUtil.toInteger(canBuy);
        return Response.success(canBuyInteger);
    }

    @GetMapping("/cancel")
    @Operation(summary = "取消订单", description = "小程序取消订单使用")
    public Response<Boolean> cancelOrder(@RequestParam String orderId) {
        return Response.success(packOrderService.cancelOrder(orderId));
    }

}
